<?php

class Sistema_Form_Pagina extends Zend_Form {

    public function init() {
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;

        $this->setName('form_' . $controller);
        $this->setAttrib('class', 'formCtrl');

        $id = $front->getRequest()->getParam('id', 0);

        $el = new Zend_Form_Element_Hidden('PAG_ID', array('disableLoadDefaultDecorators' => true));
        $el->addDecorators(array(array('ViewHelper'), array('Errors')))
                ->addFilter('Int');
        $this->addElement($el);
        
        $arr = array(
            '1' => 'Página',
            '2' => 'Subpáginas',
            '3' => 'Contato',
        ); 
        
        $el = new Zend_Form_Element_Select('PAG_TIP',array('onchange' => '')); 
        $el->setLabel('Tipo da página')
        ->setRequired(true)
        ->addMultiOptions($arr);
        $this->addElement($el);
        

        $el = new Zend_Form_Element_Text('PAG_NOM');
        $el->setLabel('Título')->setRequired(true);
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Textarea('PAG_TXT');
        $el->setLabel('Texto');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('PAG_CORBAC');
        $el->setLabel('Cor de Fundo')->setRequired(true);
        $el->setAttrib('class', 'cor');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_File('PAG_FILE');
        $el->setLabel('Imagem Geral')
	->addValidator('Extension', false, array('jpg','jpeg', 'png', 'gif'));
        $this->addElement($el);
        $img = glob('public/upload/'.$controller.'/'.$front->getRequest()->getParam('id').'.*');
        if(count($img) > 0)
        foreach($img as $src) {
            $el = new Zend_Form_Element('img',array( 'helper'=>'formNote', 'value'=>'<img src="'.$front->getBaseUrl().'/'.$src.'" />' ));
            $this->addElement($el);
        }
        
        $el = new Zend_Form_Element_File('PAG_FILE2');
        $el->setLabel('Imagem Topo - 969x220')
	->addValidator('Extension', false, array('jpg','jpeg', 'png', 'gif'));
        $this->addElement($el);
        $img = glob('public/upload/'.$controller.'/'.$front->getRequest()->getParam('id').'_tpp.*'); 
        if(count($img) > 0)
        foreach($img as $src) {
            $el = new Zend_Form_Element('img2',array( 'helper'=>'formNote', 'value'=>'<img style="max-width:600px" src="'.$front->getBaseUrl().'/'.$src.'" />' ));
            $this->addElement($el);
        }
        
        $el = new Zend_Form_Element_Text('PAG_ORD');
        $el->setLabel('Ordem')->setRequired(true);
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Checkbox('PAG_STA',array('checked'=>'checked'));
        $el->setLabel('Ativo');
        $this->addElement($el);
        
        $btn = new Zend_Form_Element_Submit('Salvar', array('disableLoadDefaultDecorators' => true));
        $btn->setLabel('Salvar');
        $btn->addDecorators(array(array('ViewHelper'), array('Errors')));
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);

        $btn = new Zend_Form_Element_Button('Cancelar', array('disableLoadDefaultDecorators' => true));
        //$btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="' . $url . '" class="btn-frm">Voltar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
    }

}
